package org.hzero.order.infra.util;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;

import com.fasterxml.jackson.databind.JsonSerializer;

/**
 * @author xiuiqng.Yang-Estelle-양수청
 * @date 2019/8/8 9:56
 */

public class DecimalSerialize extends JsonSerializer {

    //修改要除的数据
    private static final BigDecimal TEMP = BigDecimal.valueOf(1000000L);

    @Override
    public void serialize(Object value, com.fasterxml.jackson.core.JsonGenerator gen, com.fasterxml.jackson.databind.SerializerProvider serializers) throws IOException {
        if (value != null) {
            BigDecimal bigDecimal = new BigDecimal(value.toString());
            //第二个参数为保留几位小数
            gen.writeNumber(bigDecimal.divide(TEMP, 2, RoundingMode.DOWN));
        }
    }
}
